home *** CD-ROM | disk | FTP | other *** search
/ Programming in Microsoft Windows with C# / Programacion en Microsoft Windows con C#.iso / Codigo / Jugar con las fuentes / HollowFontWidePen / HollowFontWidePen.cs next >
Encoding:
Text File  |  2002-05-10  |  1.6 KB  |  48 lines

  1. //------------------------------------------------
  2. // HollowFontWidePen.cs ⌐ 2001 by Charles Petzold
  3. //------------------------------------------------
  4. using System;
  5. using System.Drawing;
  6. using System.Drawing.Drawing2D;
  7. using System.Windows.Forms;
  8.  
  9. class HollowFontWidePen: FontMenuForm
  10. {
  11.      public new static void Main()
  12.      {
  13.           Application.Run(new HollowFontWidePen());
  14.      }
  15.      public HollowFontWidePen()
  16.      {
  17.           Text = "Fuente hueca (Lßpiz grueso)";
  18.           Width *= 2; 
  19.           strText = "Lßpiz grueso";
  20.           font = new Font("Times New Roman", 108, 
  21.                           FontStyle.Bold | FontStyle.Italic);
  22.      }
  23.      protected override void DoPage(Graphics grfx, Color clr, int cx, int cy)
  24.      {
  25.           GraphicsPath path = new GraphicsPath();
  26.           float fFontSize = PointsToPageUnits(grfx, font);
  27.  
  28.                // A±adir texto al trazado.
  29.  
  30.           path.AddString(strText, font.FontFamily, (int) font.Style,
  31.                          fFontSize, new PointF(0, 0), new StringFormat());
  32.  
  33.                // Obtener los lφmites del trazado para el centrado.
  34.  
  35.           RectangleF rectfBounds = path.GetBounds();
  36.           
  37.           grfx.TranslateTransform(
  38.                          (cx - rectfBounds.Width) / 2 - rectfBounds.Left,
  39.                          (cy - rectfBounds.Height) / 2 - rectfBounds.Top);
  40.  
  41.                // Dibujar el trazado.
  42.  
  43.           Brush brush = new HatchBrush(HatchStyle.Trellis, 
  44.                                        Color.White, Color.Black);
  45.           Pen pen = new Pen(brush, fFontSize / 20);
  46.           grfx.DrawPath(pen, path);
  47.      }
  48. }